"""
购物车模块
添加购物车/清空购物车/创建交易
"""
import requests

from api.base import BaseBuyerApi
from api.buyer.login_api import BuyerLoginAPI


class CartApi(BaseBuyerApi):
    """添加购物车"""
    def __init__(self,sku_id, num=1):
        super().__init__()
        self.url = f"{self.host}/trade/carts"
        self.method = "post"
        self.data = {
            "sku_id": sku_id,
            "num": num
        }

class TradeCartsBuy(BaseBuyerApi):
    """立即购买"""
    def __init__(self,sku_id, num=1):
        super().__init__()
        self.url = f"{self.host}/trade/carts/buy"
        self.method = "post"
        self.data = {
            "sku_id": sku_id,
            "num": num
        }

class CartDelete(BaseBuyerApi):
    """清空购物车"""
    def __init__(self):
        super().__init__()
        self.url = f"{self.host}/trade/carts"
        self.method = "delete"

class Create_trade(BaseBuyerApi):
    """创建交易"""
    def __init__(self,client='PC', way='BUY_NOW'):
        super().__init__()
        self.url = 'http://59.36.173.55:7002/trade/create'
        self.method = "post"
        # 表单参数
        self.data = {
            "client": client,
            "way": way
            }

class Rog(BaseBuyerApi):
    """买家确认收货"""
    def __init__(self,order_sn):
        super().__init__()
        self.url = f"{self.host}/trade/orders/{order_sn}/rog"
        self.method = "post"


if __name__ == '__main__':
    # 调用登录接口 提取token 赋值给BaseBuyerApi.buy_token
    resp = BuyerLoginAPI().request()
    BaseBuyerApi.buy_token = resp.json()["access_token"]
    # 加入购物车
    resp = CartApi(sku_id=45518,num=1).request()
    # print(resp.status_code)
    print(resp.text)
    # 清空购物车
    # resp = CartDelete().request()
    # print(resp.status_code)
    # print(resp.text)
